#include "Aquarium.h"
#include "FishFactory.h"


Aquarium::Aquarium() {};

Aquarium* Aquarium::aquarium = NULL;

Aquarium* Aquarium::getAquarium() 
{
	if (aquarium == NULL){
		aquarium = new Aquarium();
	}
	return aquarium;
};

void Aquarium::feed() 
{
	this->notify("feed");
};

void Aquarium::debug() 
{
	this->notify("debug");
};

void Aquarium::pausePlay() 
{
	this->notify("pausePlay");
};

void Aquarium::empty() 
{
	int i;
	for (i=0; i < (int) fishes.size(); i++) {
		detach(fishes[i]);
		FishFactory::destroyFish(fishes[i]);
	}
	fishes.clear();
};

bool Aquarium::addFish(const string& fishType) 
{
	Fish *fish = FishFactory::createFish(fishType);
	if (fish == NULL) return false;
	attach(fish);
	fishes.push_back(fish);
	return true;
};

bool Aquarium::removeFish(const string& fishType) 
{
	int i;
	for (i=0; i < (int) fishes.size(); i++) {
		if (fishes[i]->getTypeStr() == fishType) {
			detach(fishes[i]);
			FishFactory::destroyFish(fishes[i]);
			fishes.erase(fishes.begin() + i);
			
			return true;
		}
	}
	return false;
};

Aquarium::Aquarium(const Aquarium& aq) {}; /*empty impl*/
const Aquarium& Aquarium::operator=(const Aquarium& aq) { return aq;}; /*empty impl*/